<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子42-ES6/7常用语法介绍</title>
    </head>

    <body>
        <pre>
            <code>
                // 例子42

                class Point {
                    constructor(x, y) {
                        this.x = x;
                        this.y = y;
                        this.getX = this.getX.bind(this); // 绑定this，保证方法单独调用不会出错
                    }

                    getX() {
                        return this.x;
                    }

                    getY() {
                        return this.y;
                    }
                }

                let p = new Point(1, 2);
                const { getX, getY } = p;
                getX(); // 1
                getY(); // Uncaught TypeError: Cannot read property 'y' of undefined

            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/42.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>

</html>